window.gridrulerContentScript = function() {
    let e = function() {
        let e = 0
          , t = jQuery(window)
          , r = jQuery("html")
          , i = jQuery(document.scrollingElement || "html")
          , l = Math.max(t.width(), r.width(), i[0].scrollWidth)
          , o = Math.max(t.height(), r.height(), i[0].scrollHeight)
          , h = jQuery("#fe-helper-ruler-top").width(l)
          , n = jQuery("#fe-helper-ruler-left").height(o);
        if (!h.children().length || h.children().last().position().left < l - 50) {
            h.html("");
            for (let t = 30; t <= l; t += 10)
                e = t % 50 ? 10 : 0,
                jQuery('<div class="h-line"></div>').appendTo("#fe-helper-ruler-top").css({
                    left: t - 1,
                    top: e + 15,
                    height: 30 - e - 5
                }),
                0 === e && 0 !== t && jQuery('<div class="h-text">' + t + "</div>").appendTo("#fe-helper-ruler-top").css({
                    left: t - 4 * String(t).length
                })
        }
        if (!n.children().length || n.children().last().position().top < o - 50) {
            n.html("");
            for (let e = 0; e <= o; e += 10)
                _l = e % 50 ? 10 : 0,
                jQuery('<div class="v-line"></div>').appendTo("#fe-helper-ruler-left").css({
                    left: _l + 15,
                    top: e - 1,
                    width: 30 - _l - 5
                }),
                0 === _l && jQuery('<div class="v-text">' + e + "</div>").appendTo("#fe-helper-ruler-left").css({
                    top: e - 4 * String(e).length,
                    left: 0 === e ? 5 : 0
                })
        }
    };
    window.gridrulerNoPage = function(t) {
        window.gridrulerContentScriptCssInject ? window.gridrulerContentScriptCssInject() : chrome.runtime.sendMessage({
            type: "fh-dynamic-any-thing",
            func: ((e,t)=>{
                let r = e=>{
                    chrome.tabs.insertCSS({
                        code: e
                    })
                }
                  , i = Awesome.getContentScript("grid-ruler", !0);
                return "string" == typeof i ? r(i) : i instanceof Promise && i.then(e=>r(e)),
                t && t(),
                !0
            }
            ).toString()
        }),
        function() {
            let e = jQuery("#fe-helper-box");
            e[0] && e.remove();
            let t = jQuery(window)
              , r = jQuery("body");
            jQuery('<div id="fe-helper-box"></div>').appendTo("body").css({
                position: "static"
            }),
            jQuery('<div id="fe-helper-grid"></div>').appendTo("#fe-helper-box").css({
                width: r.width(),
                height: Math.max(t.height(), r.height())
            }).mousemove(function(e) {
                let t = {};
                try {
                    t = document.getElementsByTagName("body")[0].getBoundingClientRect()
                } catch (e) {
                    t = {
                        left: 0,
                        top: 0
                    }
                }
                jQuery("#fe-helper-g-pos").show().css({
                    width: e.pageX - t.left,
                    height: e.pageY
                });
                let i = Math.min(e.pageY, jQuery(window).height() + r.scrollTop() - 40)
                  , l = Math.min(e.pageX, jQuery(window).width() + r.scrollLeft() - 200) + 5 - t.left;
                jQuery("#fe-helper-gp-info").show().css({
                    top: i,
                    left: l
                }).html("top = " + e.pageY + " px ,left = " + e.pageX + " px")
            }).mouseout(function(e) {
                jQuery("#fe-helper-g-pos,#fe-helper-gp-info").hide()
            }),
            jQuery('<div id="fe-helper-g-pos"></div><div id="fe-helper-gp-info"></div>').appendTo("#fe-helper-box"),
            jQuery('<span id="fe-helper-btn-close-grid">关闭栅格层</span>').appendTo("#fe-helper-box").click(function() {
                jQuery("#fe-helper-box").remove()
            })
        }(),
        jQuery("#fe-helper-box")[0] || jQuery('<div id="fe-helper-box"></div>').appendTo("body"),
        jQuery('<div id="fe-helper-ruler-top"></div><div id="fe-helper-ruler-left"></div>').appendTo("#fe-helper-box"),
        e(),
        jQuery("body").keydown(function(e) {
            jQuery("#fe-helper-box")[0] && 27 === e.which && jQuery("#fe-helper-box").remove()
        }),
        jQuery(window).resize(function() {
            if (jQuery("#fe-helper-box")[0]) {
                let t = jQuery(window)
                  , r = jQuery("body");
                jQuery("#fe-helper-grid").css({
                    width: Math.max(t.width(), r.width()),
                    height: Math.max(t.height(), r.height())
                }),
                e()
            }
        }),
        jQuery(window).scroll(function(e) {
            if (jQuery("#fe-helper-box")[0]) {
                let e = jQuery(document.scrollingElement || "html");
                jQuery("#fe-helper-ruler-top").css("left", 0 - e.scrollLeft()),
                jQuery("#fe-helper-ruler-left").css("top", 0 - e.scrollTop())
            }
        })
    }
}
;
